package com.l2jserver.gameserver.network.serverpackets;

import com.l2jserver.gameserver.model.actor.instance.L2DoorInstance;
import com.l2jserver.gameserver.util.Util;

/**
 ** @author Gnacik Edited by sefirot909
 */
public class OnEventTrigger extends L2GameServerPacket
{
	private final int _emitterId;
	private final boolean _opened;
	
	// private static final int[] REVERSE_DOORS =
	// {
	// 16200023,
	// 16200024,
	// 16200025
	// };
	
	private static final int REVERSE_DOORS[] =
	{
		0xf73157,
		0xf73158,
		0xf73159
	};
	
	public OnEventTrigger(L2DoorInstance door, boolean opened)
	{
		_emitterId = door.getEmitter();
		// XXX: Check this out!
		if (Util.contains(REVERSE_DOORS, door.getDoorId()))
		{
			_opened = !opened;
		}
		else
		{
			_opened = opened;
		}
	}
	
	// by Sefirot909
	public OnEventTrigger(int id, boolean opened)
	{
		_emitterId = id;
		_opened = opened;
	}
	
	@Override
	protected final void writeImpl()
	{
		// writeC(0xCF);
		writeC(207);
		writeD(_emitterId);
		writeD(_opened ? 0 : 1);
	}
}